from django.shortcuts import render

# Create your views here.
from django.http import HttpResponse
from showinfo.models import Birthday


def index(request):
    try:
        age_indexs = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve',
                     'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty',
                     'twenty-one', 'twenty-two', 'twenty-three', 'twenty-four', 'twenty-five', 'twenty-six',
                     'twenty-seven']
        age_infos = Birthday.objects.all()
        for inde, age_index in enumerate(age_indexs):
            context = [
                {
                    age_index: {
                        'age': age_infos[inde].age,
                        'image': age_infos[inde].image,
                        'describe': age_infos[inde].describe,
                        'index': age_infos[inde].index,
                    }
                }
            ]
        return render(request, 'index.html', context)
    except Exception as e:
        return HttpResponse("{0}".format(str(e)))
